home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / SETUSRSZ.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.6 KB  |  62 lines

  1. /* setusrsz.c  --- setusercharsize */
  2. /* copied from Turbo C Bible, page 859-861 */
  3. #include <graphics.h>
  4. char long_title[]=
  5.     {"This title has been scaled to fit inside this box"};
  6. main()
  7. {
  8.     int graphdriver = DETECT, graphmode,xmax,ymax,xsize,ysize,
  9.         textx,texty,multx,multy,divx,divy;
  10.     double ratio;
  11.                     /* Detect and initialize graphics system */
  12.     initgraph(&graphdriver, &graphmode, "c:\\turboc");
  13.                     /* Define a viewport */
  14.     xmax = getmaxx();
  15.     ymax = getmaxy();
  16.     xsize = xmax - 100;
  17.     ysize = ymax/5;
  18.     setviewport(50, 30, xsize+50, ysize+30, 1);
  19.     setfillstyle(SOLID_FILL, RED);
  20.     bar3d(0,0,xsize,ysize,0,1);
  21.     setcolor(YELLOW);
  22.     settextjustify(CENTER_TEXT,CENTER_TEXT);
  23.             /* Define the scaling necessary to fit title in box.
  24.              * The integers fed to setusercharsize must not be
  25.              * large. For example,
  26.              *   setusercharsize(500,750,1,1) fails to scale. */
  27.     settextstyle(TRIPLEX_FONT,HORIZ_DIR,0);
  28.     setusercharsize(1,1,1,1);
  29.     textx = textwidth(long_title);
  30.     texty = textheight(long_title);
  31.                 /* If title fits, leave it untouched */
  32.     if(textx < xsize)
  33.     {
  34.         multx = 1;
  35.         divx = 1;
  36.     }
  37.     else
  38.     {
  39.         ratio = 10.*(double)xsize/(double)textx;
  40.         multx = (int)ratio;
  41.         divx = 1;
  42.     }
  43.     if (texty < ysize)
  44.     {
  45.         multy = 1;
  46.         divy = 1;
  47.     }
  48.     else
  49.     {
  50.         ratio = 10.*(double)ysize/(double)texty;
  51.         multy = (int)ratio;
  52.         divy = 10;
  53.     }
  54.                     /* Now set scale and print title */
  55.     setusercharsize(multx,divx,multy,divy);
  56.     settextstyle(TRIPLEX_FONT, HORIZ_DIR, 0);
  57.     outtextxy(xsize/2,ysize/2, long_title);
  58.                     /* Wait for a key press. */
  59.     getch();
  60.                     /* Close graphics system when done */
  61.     closegraph();
  62. }